<template>
  <div class="table-content">
    <el-table class="table-box" :data="products" stripe style="width: 80%" border>
      <el-table-column prop="brand" label="品牌" align="center"></el-table-column>
      <el-table-column prop="model" label="型号" align="center"></el-table-column>
      <el-table-column prop="count" label="数量" align="center"></el-table-column>
      <el-table-column
        prop="ram"
        label="运行内存"
        align="center"
        :filters="ram_filter"
        :filter-method="ram_filter_method"
      />
      <el-table-column prop="storage" label="存储容量" align="center"></el-table-column>
      <el-table-column prop="color" label="颜色" align="center"></el-table-column>
      <el-table-column label="串码" align="center">
        <template slot-scope="scope">
          <el-select v-model="scope.row.checkIMEI" placeholder="请选择">
            <el-option v-for="item in scope.row.imei" :key="item" :label="item" :value="item"></el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">出库</el-button>
          <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import GLOBAL from '@/GLOBAL'
export default {
  props: ['products'],
  data() {
    return {
      checkIMEI: '',
      ram_filter: [],
      storage_filter: [],
    }
  },
  mounted() {
    this.init_filter()
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row)
      this.$http
        .patch(`/product/${row._id}`, {
          product: row,
          name: '小明',
          time: Date.now(),
        })
        .then(res => {
          console.log(res.data)
          this.$message({
            type: 'success',
            message: '出库成功',
          })
          this.$emit('update_data')
        })
    },
    handleDelete(index, row) {
      console.log(index, row)
      this.$http.patch(`/product/imei/${row._id}`, row).then(res => {
        console.log(res.data)
        this.$message({
          type: 'success',
          message: '删除成功',
        })
        this.$emit('update_data')
      })
    },
    ram_filter_method() {},
    init_filter() {
      for (let ram of GLOBAL.rams) {
        this.ram_filter.push({
          value: ram,
          text: ram,
        })
      }
    },
    update_father() {
      this.$emit('update_data')
    },
  },
}
</script>

<style scoped>
.table-box {
  margin: 0 auto;
}
</style>
